package org.ronghao.androidwifiplatfrom.entity;

import org.json.JSONException;
import org.json.JSONObject;
import org.ronghao.androidwifiplatfrom.utils.Contants;

public class Game {
	private int id;// 该游戏的ID
	private String gameName;// 游戏名称
	private String gamePassword;// 游戏密码
	private int gameID;// 游戏对应的ID
	private int gameTotleNum;// 游戏最大人数

	public Game() {
	}

	public Game(String msg) {
		try {
			JSONObject jsonObject = new JSONObject(msg);
			setId(jsonObject.getInt(Contants.COMMUNICATION_GAME_ID));
			gameName = jsonObject
					.getString(Contants.COMMUNICATION_GAME_GAMENAME);
			gamePassword = jsonObject
					.getString(Contants.COMMUNICATION_GAME_GAMEPASSWORD);
			gameID = jsonObject.getInt(Contants.COMMUNICATION_GAME_GAMEID);
			gameTotleNum = jsonObject
					.getInt(Contants.COMMUNICATION_GAME_GAMETOTLENUM);
		} catch (JSONException e) {
			setId(-1);
			gameName = "";
			gamePassword = "";
			gameID = 1;
			gameTotleNum = 2;
		}
	}
	
	public String gameToString(){
		return Contants.objToJsonString(this);
	}


	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getGameName() {
		return gameName;
	}

	public void setGameName(String gameName) {
		this.gameName = gameName;
	}

	public String getGamePassword() {
		return gamePassword;
	}

	public void setGamePassword(String gamePassword) {
		this.gamePassword = gamePassword;
	}

	public int getGameID() {
		return gameID;
	}

	public void setGameID(int gameID) {
		this.gameID = gameID;
	}

	public int getGameTotleNum() {
		return gameTotleNum;
	}

	public void setGameTotleNum(int gameTotleNum) {
		this.gameTotleNum = gameTotleNum;
	}
}
